{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item" id="fordaochu">
                        <div class="layui-input-inline layui-form">
                            <select name="status" class="layui-input">
                                <option  value="">不限状态</option>
                                <option  value="1">收入</option>
                                <option  value="2">退回</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="one_type" class="layui-input">
                                <option  value="">不限订单类型</option>
                                <option  value="1">自营订单</option>
                                <option  value="2">增补订单</option>
                                <option  value="3">统购订单</option>
                                <option  value="4">退款订单</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <input type="text"  name="start" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="开始日期" />
                        </div>
                        <div class="layui-input-inline">
                            <input type="text"  name="end" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="结束日期" />
                        </div>
                        <div class="layui-input-inline">
                            <input type="text"  name="number"  class="layui-input layer-date search" placeholder="流水单号|用户手机号" />
                        </div>

                        <div class="layui-input-inline" style="width: 100%;">
                            <br/>
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            <button type="button" onclick="daochu();" class="layui-btn"><i class="layui-icon layui-icon-export"></i>导出</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <input type="text" disabled class="layui-input" id="tongji1" value="总营收金额：{$pay}          总退还金额：{$unpay}" style="border:1px solid red;color: red;width: 300px;" />
                    </div>
                </div>
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                    <!--状态显示模板-->
                    <script type="text/html" id="authtype">
                        {{# if(d.revenue_type == 1){ }}
                        <span style="color: red;font-weight: bold;font-size: 16px">+</span>
                        {{# } }}
                        {{# if(d.revenue_type == 2){ }}
                        <span style="color: #000;font-weight: bold;font-size: 16px">-</span>
                        {{# } }}
                    </script>
                    <script type="text/html" id="pay_type">
                        {{# if(d.pay_type == 1){ }}
                        <span>微信</span>
                        {{# } }}
                        {{# if(d.pay_type == 2){ }}
                        <span>支付宝</span>
                        {{# } }}
                        {{# if(d.pay_type == 3){ }}
                        <span>银联</span>
                        {{# } }}
                    </script>
                    <script type="text/html" id="statBar">
                        {{# if(d.revenue_one_type == 1){ }}
                        自营订单
                        {{# } }}
                        {{# if(d.revenue_one_type == 2){ }}
                        增补订单
                        {{# } }}
                        {{# if(d.revenue_one_type == 3){ }}
                        统购订单
                        {{# } }}
                        {{# if(d.revenue_one_type == 4){ }}
                        退款订单
                        {{# } }}
                    </script>
                    <script type="text/html" id="forfor">
                        {{# if(d.revenue_type == 1){ }}
                        id：{{d.revenue_order_id}}
                        {{# } }}
                        {{# if(d.revenue_type == 2){ }}
                        操作者：{{d.revenue_admin_id}}
                        {{# } }}
                    </script>
                    <!--状态显示模板-->
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('account')}?id={{d.dl_id}}')" class="btn btn-primary btn-xs m-r-xs">查看详情</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("money/water")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
//            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left',}
                {type:'numbers', width: 70, title: '序号'}
                , {field: 'revenue_number', width: '150', title: '流水单号', align: 'center'}
                , {field: 'revenue_money', width: '80', title: '金额', align: 'center'}
                , {field: 'revenue_type', width: '80', title: '类型', align: 'center', toolbar: '#authtype'}
                , {field: 'revenue_one_type', width: '100', title: '订单类型', align: 'center', toolbar: '#statBar'}
                , {field: 'pay_type', width: '100', title: '支付方式', align: 'center', toolbar: '#pay_type'}
                , {field: 'revenue_type', width: '', title: '订单id/管理员', align: 'center', toolbar: '#forfor'}
                , {field: 'user_username', width: '', title: '用户名称', align: 'center'}
                , {field: 'user_phone', width: '', title: '用户电话', align: 'center'}
                , {field: 'revenue_time', width: '', title: '时间', align: 'center'}
//                , {fixed: 'right', width: '', title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("memberState")}',obj);
        });

        //批量操作
        var $ = layui.$, active = {
            excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$('.layui-input').serialize(),"{:url('excelMember')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['user_id'])
            });
            return ids;
        }
    });

    function daochu() {
        layer.confirm('确认导出数据吗？', {icon: 3, title:'提示'}, function(index){
            var str = '';
            $('#fordaochu .layui-input').each(function (i,d) {
                var name = $(d).attr('name');
                var value = $(d).val();
                if(name && value){
                    str += name + '=' + value + '&';
                }

            });
            str = str.slice(0, -1);
            var loading = layer.msg('正在处理数据，请勿关闭页面...', {icon: 16,shade: 0.4,time:false});
            $.ajax({
                url: '/admin/Money/excelwater',
                data: str,
                type: 'POST',
                dataType: 'JSON',
                success: function (returnData) {
                    if(returnData.code == 200){
                        location.href = (returnData.msg);
                    }
                    layer.close(loading);
                },
                error: function () {
                    alert('数据出错，请刷新重试');
                }
            })
            layer.close(index);
        })
    }
</script>
</body>
</html>